package controller;

import model.Admin;
import model.Teacher;
import model.query.HQL;

/**
 *
 * @author cska
 * 
 */
public class LoginCtrl {

    protected String login;
    protected String pass;
    protected Long id;

    public LoginCtrl(String login, String pass) {
        this.login = login;
        this.pass = pass;
    }

    public boolean canLogin() {
        return isAdmin() || isTeacher();
    }

    public boolean isAdmin() {
        boolean fl = false;
        for (Admin admin : HQL.getSelect().admins()) {
            if ((login.equals(admin.getLogin())) && (pass.equals(admin.getPass()))) {
                fl = true;
                break;
            }
        }
        return fl;
    }

    public boolean isTeacher() {
        boolean fl = false;
        for (Teacher teacher : HQL.getSelect().teachers()) {
            if (login.equals(teacher.getLogin()) && pass.equals(teacher.getPass())) {
                fl = true;
                id = teacher.getId();
                break;
            }
        }
        return fl;
    }

    public Teacher getTeacher() {
        return HQL.getSelect().teacher(id);
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    public String getLogin() {
        return login;
    }

    public String getPass() {
        return pass;
    }
}
